﻿u = 0;
function frame1Actions() {
	stop();
	_root.onEnterFrame = function() {
		u++;
		if( u > 10 ) {
			gotoAndStop(2);
		}
	}
	button.onRelease = function() {
		gotoAndStop(2);
	}
	
}

function stopPlayer() {
	getURL("javascript:fg_removeMp3Player('"+_root.playerName+"','"+_root.song+"','"+_root.playerLocation+"')");
	songTrack.stop();
	songTrack.onLoad = function() {}
}

function calculateTime() {
	var pos = songTrack.position;
	
	var seconds = Math.ceil(pos/1000);
	var minutes = Math.floor(seconds/60);
	seconds = seconds%60;

	if( minutes < 10 )
		minutes = "0"+minutes.toString();
	
	if( seconds < 10 )
		seconds = "0"+seconds.toString();
		
	return minutes+":"+seconds;
}

function frame2Actions() {
	
	songTrack = new Sound();
	songTrack.onLoad = function() {}
	songTrack.loadSound(_root.song, true);
	
	songTrack.onLoad = function () {
		_root.gotoAndStop(3);
	}
	
	_root.onEnterFrame = function() {
		trackPos = calculateTime();
	}
	
	button.onRelease = function() {
		stopPlayer();
	}
}

function frame3Actions() {
	_root.onEnterFrame = function() {
		
		trackPos = calculateTime();
		
		pos = songTrack.position
		if( pos >= songTrack.duration ) {
			stopPlayer();
		}
		
		if( pos >= songTrack.duration-2000) {
			if( songTrack.getVolume() > 0 ) {
				songTrack.setVolume( songTrack.getVolume()-4 );
			} else {
				songTrack.setVolume(0);
			}
		}	
	}
}